import { Component, OnInit } from '@angular/core';
import { Config } from '../model/config';
import { ConfigService } from './config.service';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';

@Component({
  selector: 'app-config',
  templateUrl: './config.component.html',
  styleUrls: ['./config.component.less']
})
export class ConfigComponent implements OnInit {
  config: Config;
  headers: string[];

  constructor(private configService: ConfigService,
    private router: Router) { }

  ngOnInit(): void {
  }

  showConfig() {
    this.configService.getConfig()
      .subscribe((data: Config) => this.config = {
        ...data
      });
  }

  showConfigResponse() {
    this.configService.getConfigResponse()
    .subscribe( resp => {
      const keys = resp.headers.keys();
      this.headers = keys.map(key => `${key}: ${resp.headers.get(key)}`);
      this.config = { ... resp.body };
    })
  }

}
